import db from './createDb'
import Mock from 'mockjs'
import md5 from 'md5'
// 注册模块
Mock.mock('user/register', 'post', (info) => {
  const { userName, password } = JSON.parse(info.body)
  const result = db.select('zy_users', item => item.userName === userName)
  // 判断用户名是否存在
  if (result && result.length) {
    return {
      err: 1002,
      desc: '该账号已被注册,请重新输入账号'
    }
  }
  db.add('zy_users', { userName, password: md5(password), state: 1 })
  return {
    err: 0,
    desc: '注册成功'
  }
})
